﻿#include "mradddialog.h"
#include "ui_mradddialog.h"

#include <QDate>

MRaddDialog::MRaddDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MRaddDialog)
{
    ui->setupUi(this);
    ui->dateEdit->setDate(QDate::currentDate());
    ui->frame->resize(this->geometry().width(), ui->frame->height());
    ui->status->setText("添加信息状态：");
    connect(ui->cancelbtn,SIGNAL(clicked(bool)),this,SLOT(close()));
    connect(ui->ackbtn,SIGNAL(clicked(bool)),parent,SLOT(MRshowdatabase()));
}

MRaddDialog::~MRaddDialog()
{
    delete ui;}

void MRaddDialog::on_ackbtn_clicked()
{
    if(ui->copies->text().isEmpty()||ui->unit->text().isEmpty()||ui->content->text().isEmpty())
    {
        ui->status->setText("添加信息状态:请至少添入接收日期，接收单位，接收内容，份数");
       } else{
    QSqlQuery qu;
    qu.prepare("INSERT INTO ZZB.MaterialReceive(ReceiveID,ReceiveDate,OriginalUnit,OriginalEnvelope,Copies,MaterialContent)"
                  "VALUES(:ReceiveID,:ReceiveDate,:OriginalUnit,:OriginalEnvelope,:Copies,:MaterialContent)");

    qu.bindValue(":ReceiveDate",ui->dateEdit->text());
    qu.bindValue(":OriginalUnit",ui->unit->text());
    qu.bindValue(":OriginalEnvelope",ui->envelope->text());
    qu.bindValue(":Copies",ui->copies->text());
    qu.bindValue(":MaterialContent",ui->content->text());

    bool ok=qu.exec();
    if(ok)
    {ui->status->setText("添加信息状态:添加成功");
        ui->envelope->clear();
        ui->content->clear();
        ui->copies->clear();
        ui->unit->clear();}
    else
    {ui->status->setText("添加信息状态:添加失败");}
}
}
